 <html>
 <head>
 	<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/themes/{$themes}/easyui.css">
 	<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/css/themes/main.css">
 	<script type="text/javascript" src="__PUBLIC__/js/jquery.min.js"></script>
 	<script type="text/javascript" src="__PUBLIC__/js/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="__PUBLIC__/js/validate.js"></script>
 	<script type="text/javascript" src="__PUBLIC__/js/json2.js"></script>
    <script type="text/javascript" src="__PUBLIC__/js/locale/easyui-lang-{$lang}.js"></script>
 	<script type="text/javascript">
 		$(function(){
 			loadMenu();
 			BindTabsMenu();
 		});

	 	function onChangeTheme(theme){
	 		if(theme) {
	 			var link = $(document).find('link:first');
	 			var link_href = link.attr('href');
	 			var i = link_href.indexOf("/themes/");
	 			link_href = link_href.substr(0,i+8)+theme+'/easyui.css';
	 			link.attr('href', link_href);
	 			$.get('/OA/Admin/Index/saveThemes/?themes=' + theme);
	 		}
		}
		function onChangeLang(lang) {
			if(lang){
				var url = '/OA/Admin/?l=' + lang;
				location.href = url;
	 			$.get('/OA/Admin/Index/saveLang/?l=' + lang);
			}
		}
		function loadMenu() {
			$.ajax({
                type: 'POST',
                datatype: 'json',
                url: '/OA/Admin/Index/getModule',
                success: function (data) {
                    $.each(data, function (i, item) {
                        var str_content = JSON.stringify(item.children);
                        str_content = "<ul class='easyui-tree' data-options='data:" + str_content +
                            ",animate:true,lines:true,onClick:function(node){onNodeClick(node);}'></ul>";
                        $('#pMenu').accordion('add', {
                            title: item.text,
                            selected: false,
                            content: str_content,
                            iconCls: item.iconCls
                        });
                    });
                }
            });
		}
		function onNodeClick(node){
			LoadPage(node.id,node.text,node.attributes.url,node.attributes.parameter,node.attributes.target,node.attributes.icon);
		}
 		//加载页面
        function LoadPage(id, title, url, parameter, target, icon) {
            var obj = $('#pMain').tabs('tabs');
            if (obj.length > 5) {
                $.messager.alert("lan_tip", "tip_over", 'info');
                return;
            }
            url = url + "?_mid=" + id;
            if (parameter != "") url += "&" + parameter;
            switch (target) {
                case "_blank":
                    window.open(url);
                    break;
                case "_top":
                    top.location.href = url;
                    break;
                case "_content":
                	var content = '<iframe scrolling="no" frameborder="0"  src="' + url + '" style="width:100%;height:99%;"></iframe>';
                    if (!$('#pMain').tabs('exists', title)) {
                        $('#pMain').tabs('add', {
                            title: title,
                            content: content,
                            iconCls: icon,
                            closable: true
                        });
                    } else {
                        $('#pMain').tabs('select', title);
                    }
                    break;
                default:
                    if (!$('#pMain').tabs('exists', title)) {
                        $('#pMain').tabs('add', {
                            title: title,
                            href: url,
                            iconCls: icon,
                            closable: true
                        });
                    } else {
                        $('#pMain').tabs('select', title);
                    }
                    break;
            }
        }  
        function RefreshTab () {
            var tab = $("#pMain").tabs('getSelected');
            tab.panel('refresh');
        }
        function query () {
            
        }
        //关闭当前页面
        function CloseTab() {
            var tab = $("#pMain").tabs('getSelected');
            var index = $('#pMain').tabs('getTabIndex', tab);
            $('#pMain').tabs('close', index);
        }  
        //绑定tabs右键菜单
        function BindTabsMenu() {
            //关闭当前标签页
            $("#closecur").bind("click", function () {
                var tab = $('#pMain').tabs('getSelected');
                var index = $('#pMain').tabs('getTabIndex', tab);
                $('#pMain').tabs('close', index);
            });
            //关闭所有标签页
            $("#closeall").bind("click", function () {
                var tablist = $('#pMain').tabs('tabs');
                for (var i = tablist.length - 1; i >= 0; i--) {
                    $('#pMain').tabs('close', i);
                }
            });
            //关闭非当前标签页（先关闭右侧，再关闭左侧）
            $("#closeother").bind("click", function () {
                var tablist = $('#pMain').tabs('tabs');
                var tab = $('#pMain').tabs('getSelected');
                var index = $('#pMain').tabs('getTabIndex', tab);
                for (var i = tablist.length - 1; i > index; i--) {
                    $('#pMain').tabs('close', i);
                }
                var num = index - 1;
                for (var i = num; i >= 0; i--) {
                    $('#pMain').tabs('close', 0);
                }
            });
            //关闭当前标签页右侧标签页
            $("#closeright").bind("click", function () {
                var tablist = $('#pMain').tabs('tabs');
                var tab = $('#pMain').tabs('getSelected');
                var index = $('#pMain').tabs('getTabIndex', tab);
                for (var i = tablist.length - 1; i > index; i--) {
                    $('#pMain').tabs('close', i);
                }
            });
            //关闭当前标签页左侧标签页
            $("#closeleft").bind("click", function () {
                var tab = $('#pMain').tabs('getSelected');
                var index = $('#pMain').tabs('getTabIndex', tab);
                var num = index - 1;
                for (var i = 0; i <= num; i++) {
                    $('#pMain').tabs('close', 0);
                }
            });
            //绑定到tab header右键
            $(".tabs-header").bind('contextmenu', function (e) {
                e.preventDefault();
                $('#rcmenu').menu('show', {
                    left: e.pageX,
                    top: e.pageY
                });
            });
        }    
 	</script>
   	<title>Home Page</title>
 </head>
 <body class="easyui-layout">
 	<div data-options="region:'north'" style="height:100px">
 		<br/>
        <a id="btn_test" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search',iconAlign:'top',plain:true,width:56">Test</a>
		<input class="easyui-combobox" name="themes" data-options="valueField:'id',textField:'text',url:'__MODULE__/Index/getThemes',onChange:onChangeTheme">
		<input class="easyui-combobox" name="language" data-options="valueField:'lan_code',textField:'lan_name',url:'__MODULE__/Index/getLanguage',onChange:onChangeLang">
 	</div>
 	<div data-options="region:'west',split:true" title="{$menu}" style="width:180px;">
 		<div id="pMenu" class="easyui-accordion" data-options="fit:true,border:false"></div>
 	</div>
 	<div data-options="region:'center',iconCls:'icon-ok'">
 		<div id="pMain" class="easyui-tabs" data-options="fit:true,border:false"></div>
        <div id="rcmenu" class="easyui-menu" style="">
            <div data-options="iconCls:'icon-cancel'" id="closecur">
                {$close_current}
            </div>
            <div id="closeall">
                {$close_all}
            </div>
            <div id="closeother">
                {$close_other}
            </div>
            <div class="menu-sep"></div>
            <div id="closeright">
                {$close_right}
            </div>
            <div id="closeleft">
                {$close_left}
            </div>
        </div>
	</div>
 </body>
 <script type="text/javascript">
 	//增加datagrid单元格编辑功能
	$.extend($.fn.datagrid.methods, {
		editCell: function(jq,param){
			return jq.each(function(){
				var opts = $(this).datagrid('options');
				var fields = $(this).datagrid('getColumnFields',true).concat($(this).datagrid('getColumnFields'));
				for(var i=0; i<fields.length; i++){
					var col = $(this).datagrid('getColumnOption', fields[i]);
					col.editor1 = col.editor;
					if (fields[i] != param.field){
						col.editor = null;
					}
				}
				$(this).datagrid('beginEdit', param.index);
				for(var i=0; i<fields.length; i++){
					var col = $(this).datagrid('getColumnOption', fields[i]);
					col.editor = col.editor1;
				}
			});
		},
        addEditor: function (jq, param) {
            if (param instanceof Array) {
                $.each(param, function (index, item) {
                    var e = $(jq).datagrid('getColumnOption', item.field);
                    e.editor = item.editor;
                });
            } else {
                var e = $(jq).datagrid('getColumnOption', param.field);
                e.editor = param.editor;
            }
        },
        removeEditor: function (jq, param) {
            if (param instanceof Array) {
                $.each(param, function (index, item) {
                    var e = $(jq).datagrid('getColumnOption', item);
                    e.editor = {};
                });
            } else {
                var e = $(jq).datagrid('getColumnOption', param);
                e.editor = {};
            }
        }
	});
	function endEditing(dg){
		var editIndex = dg.attr('editIndex');
		if(editIndex == undefined){return true}
		if (dg.datagrid('validateRow', editIndex)){
			dg.datagrid('endEdit', editIndex);
			dg.removeAttr('editIndex');
			return true;
		} else {
			return false;
		}
	}
	function onClickCell(index, field){
		var dg = $(this);
		if (endEditing(dg)){
			dg.datagrid('selectRow', index).datagrid('editCell', {index:index,field:field});
			dg.attr('editIndex', index);
		}
	}
	function onClickRow(index){
		var dg = $(this);
		var editIndex = dg.attr('editIndex');
		if(editIndex != index){
			if (endEditing(dg)){
				dg.datagrid('selectRow', index).datagrid('beginEdit', index);
				dg.attr('editIndex', index);
			} else {
				dg.datagrid('selectRow', editIndex);
			}
		}
	}
    function append (dg) {
        if (endEditing(dg)){                
            dg.datagrid('appendRow',{});                
            var editIndex = dg.datagrid('getRows').length-1;                
            dg.datagrid('selectRow', editIndex).datagrid('beginEdit', editIndex); 
            dg.attr('editIndex', editIndex);           
        }
    }
	function removeit(dg){
		var row = dg.datagrid('getSelected');
		if(!row){return}
		var selectIndex = dg.datagrid('getRowIndex', row);
		dg.datagrid('cancelEdit', selectIndex).datagrid('deleteRow', selectIndex);
        dg.removeAttr('editIndex');
	}
	function accept(dg){
		if (endEditing(dg)){
			dg.datagrid('acceptChanges');
		}
	}
	function reject(dg){
		dg.datagrid('rejectChanges');
	}
	function getChanges(dg){
		var rows = dg.datagrid('getChanges');
		return rows;
	}
    function reloadData (dg) {
        dg.datagrid('reload', {});
    }
    //打开综合查询页面
    function openQueryForm (mid, fun_Save) {
        $("<div/>").dialog({
            id: 'dlg_query',
            href: '/OA/Admin/Base/query?mid=' + mid,
            title: WIN_TITLE.ADD,
            height: 500,
            width: 600,
            modal: true,
            buttons:[{
                text: BUTTON_TITLE.OK,
                width:80,
                iconCls: 'icon-ok',
                handler: fun_Save
            },{
                text: BUTTON_TITLE.CANCEL,
                width:80,
                iconCls: 'icon-cancel',
                handler: function(){
                    $('#dlg_query').dialog('close');
                }
            }],
            onLoad: function () {
                loadQueryParameters(mid);
            },
            onClose: function () {
                $("#dlg_query").dialog('destroy');
            }
        });
    }

    function funTest () {
        alert('test');
    }
 </script>
 </html>